package com.dz.lm.web.controller.userfeedback;

import com.alibaba.fastjson.JSONObject;
import com.dz.lm.common.exception.ServiceException;
import com.dz.lm.common.utils.json.JsonUtils;
import com.dz.lm.service.feedback.FeedbackService;
import com.dz.lm.web.controller.BasicControl;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

import java.io.IOException;
import java.util.Map;

@RestController
@RequestMapping(value = "/rewriteUrl/feedback", produces = "application/json")
public class FeedbackController extends BasicControl{

	public Logger logger = LogManager.getLogger(FeedbackController.class);
    
    @Autowired
    private FeedbackService feedbackService;
    
    /**
     * 用户反馈处理
     * @return
     * @throws IOException
     */
    @ResponseBody
    @RequestMapping("/submitFeedback")
    public Map<String, Object> submitFeedback(HttpServletRequest request) throws ServiceException {
		String reqData = request.getAttribute("reqData") != null ? request.getAttribute("reqData").toString() : "";
    	JSONObject _reqData = JSONObject.parseObject(reqData);
		Map<String, Object> param = JsonUtils.readValue(_reqData.toString());
		//用户编码
		param.put("userId", request.getAttribute("userId"));
		int count = feedbackService.submitFeedback(param);
		JSONObject subjo = new JSONObject();
		if (count == 1) {
			subjo.put("result", "00");
	    	subjo.put("message", "提交成功");
		} else {
			subjo.put("result", "01");
	    	subjo.put("message", "提交失败");
		}
		return parameterEncrypt(request, subjo);
    }
}
